<?php
// Upload

class Upload extends CI_Controller {

	public function __construct()
	{
		parent::__construct();

		// autoload.php
		// library: Thank_auth, database
		// helper: url
		
		require('/assets/fineuploader/server/uploader.php');
		
		if($this->tank_auth->is_logged_in())
		{
			// user id
			$this->uid = $this->tank_auth->get_user_id();
			$this->path = './assets/uploads/';
		}
		else
		{
			$this->param = '0';
		}
	}

	public function index()
	{
		
		
		// list of valid extensions, ex. array("jpeg", "xml", "bmp")
		$allowedExtensions = array();
		// max file size in bytes
		$sizeLimit = 200 * 1024;
		
		//require('valums-file-uploader/server/php.php');
		$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
		
		// Create folder if needed
		$this->create_folder();
		
		// Call handleUpload() with the name of the folder, relative to PHP's getcwd()
		$result = $uploader->handleUpload($this->path.$this->tank_auth->get_user_id());
		
		// to pass data through iframe you will need to encode all html tags
		echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
	}
	
	private function create_folder()
	{
		if($this->tank_auth->is_logged_in())
		{
			if(!file_exists($this->path.$this->tank_auth->get_user_id()))
			{
				mkdir($this->path.$this->tank_auth->get_user_id());
			}
		}
	}
}
?>